// 配置路由
// 引入
import VueRouter from "vue-router"
import Vue from "vue"
import Layout from "@/layout"
// 2、注册全局组件
Vue.use(VueRouter)

// 3、定义路由规则
const routes = [
    {
        path: "/",
        component: Layout,
        redirect: '/index',
        children: [
            {     // 首页
                path: "/index",
                component: () => import("@/views/index/index.vue")
            }
        ]
    },     
    {
        path: '/property',
        component: Layout,
        children: [
            {     // 首页
                path: "/property",
                component: () => import("@/views/property/Property")
            }
        ]
    },
    {
        path: '/test',
        component: Layout,
        children: [
            {     // 首页
                path: "/test",
                component: () => import("@/views/test")
            }
        ]
    },
    {
        path: '/category',
        component: Layout,
        children: [
            {     // 首页
                path: "/category",
                component: () => import("@/views/category")
            }
        ]
    },
    {
        path: '/page',
        component: Layout,
        children: [
            {     // 首页
                path: "/page",
                component: () => import("@/views/page")
            }
        ]
    },
    {
        // 房产经纪
       path: '/agents',
       component: Layout,
       children: [
           {     // 首页
               path: "/agents",
               component: () => import("@/views/agents/agents.vue")
           }
       ]
   },
   {
      //地产详情 
      path: '/detail',
      component: Layout,
      children: [
          {     // 首页
              path: "/detail",
              component: () => import('@/views/detail/detail.vue')
          }
      ]
  },



]

// 4、生成路由对象
const router = new VueRouter({
    routes
})

// 解决重复跳转到同一个路由地址报错问题
// 解决跳转页面之前进行重定向报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 5、导出路由对象
export default router